#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <unistd.h>

#define MAXLINE 10
#define SERV_PORT 8888

int main(int argc, char *argv[]){
	struct sockaddr_in servaddr;
	char buf[MAXLINE];
	int sockfd, i;
	char ch = 'a';

	sockfd = socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr,sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(SERV_PORT);
	inet_pton(AF_INET, argv[1], &servaddr.sin_addr.s_addr);
	//servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	
	connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr));

	while(1){
		// aaaa\n
		for(i=0; i<MAXLINE/2; i++){
			buf[i] = ch;
		}

		buf[i-1] = '\n';
		ch++;

		// bbbb\n
		for(i; i<MAXLINE; i++){
			buf[i] = ch;
		}
		buf[i-1] = '\n';
		ch++;

		write(sockfd, buf, sizeof(buf));
		sleep(2);

	}
	close(sockfd);
	return 0;
}

